package org.phalanx.client.mapeditor;

import java.awt.Color;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

import org.phalanx.client.PhalanxClient;
import org.phalanx.map.MapTileSet;
import org.phalanx.map.PhalanxMap;

public class PhalanxEditorDisplayViewPanel extends JPanel {
	private PhalanxMapEditorPanel editorPanel;
	private PhalanxMap map;
	private PhalanxMapEditorView editorMapView;
	private TitledBorder titleBorder;

	public PhalanxEditorDisplayViewPanel(PhalanxMapEditorPanel edit) {
		this.editorPanel = edit;
		initializePanel();
	}

	private void initializePanel() {
		this.setBackground(Color.black);
		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		setUpBorder();
		createMapEditorView();

		this.add(editorMapView);
	}

	private void createMapEditorView() {
		createDefaultBlankMap();
		editorMapView = new PhalanxMapEditorView(map);
	}

	private void createDefaultBlankMap() {
		MapTileSet t = PhalanxClient.getClientInstance().getDefaultTileSet();
		map = new PhalanxMap();
		map.setMapTileSet(t);
		map.setMapDimensions(20, 20);
		map.setDefaultMapTile(t.getMapTileByName("Water1"), true);
	}

	private void setUpBorder() {
		this.setTitle("Untitled");
	}
	
	public void setTitle(String title) {
		titleBorder = BorderFactory.createTitledBorder(title);
		titleBorder.setTitleColor(Color.white);
		this.setBorder(titleBorder);
		this.updateUI();
	}

	public PhalanxMapEditorView getMapViewObject() {
		return editorMapView;
	}

	public void setMapObject(PhalanxMap newMap) {
		editorMapView.setMap(newMap);
		editorMapView.setCoordinates(0, 0);
		editorMapView.repaint();
	}
}
